import { getAppDataSource } from '@/db/index'
import { User } from '@/db/entity'

export async function POST(request: Request) {
  const body = await request.json()
  const user = new User()
  user.nickname = body.username
  user.job = body.username
  user.avatar = body.username
  user.introduce = body.username
  const AppDataSource = await getAppDataSource()
  const userRepository = AppDataSource.getRepository(User)
  console.log(userRepository)
  const currentUser = await userRepository.save(user)

  // const savedUsers = await userRepository.find()
  // console.log("All Users from the db: ", savedUsers)




  console.log('request', body)
  const data = {
    code: 200,
    result: true,
    data: currentUser
  }
  return new Response(JSON.stringify(data, null, 4));
}
